package com.benworks.test.matcher;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.springframework.core.annotation.Order;

public class OrderMatcher extends BaseMatcher<Order> {

	private final Order expected;
	private final StringBuilder errors = new StringBuilder();

	private OrderMatcher(Order expected) {
		this.expected = expected;
	}

	public boolean matches(Object item) {
//		if (!(item instanceof Order)) {
//			errors.append("received item is not of Order type");
//			return false;
//		}
//		Order actual = (Order) item;
//		if (actual.getQuantity() != (expected.getQuantity())) {
//			errors.append("received item had quantity ").append(actual.getQuantity()).append(". Expected ")
//					.append(expected.getQuantity());
//			return false;
//		}
		return true;
	}

	public void describeTo(Description description) {
		description.appendText(errors.toString());
	}

	@Factory
	public static OrderMatcher isOrder(Order expected) {
		return new OrderMatcher(expected);
	}

}